﻿function FadeVisibleHandler() {
    this.init = function (element, valueAccessor) {
        // Initially set the element to be instantly visible/hidden depending on the value
        var value = ko.utils.unwrapObservable(valueAccessor());
        $(element).toggle(value);
    };
    this.update = function (element, valueAccessor) {
        // Whenever the value subsequently changes, slowly fade the element in or out
        var value = ko.utils.unwrapObservable(valueAccessor());
        if (value) {
            setTimeout(function () {
                $(element).parent().removeClass('display-none');
                $(element).fadeIn(500); 
             }, 501);
            setTimeout(function () { $(element).accordion('resize'); }, 505);
        }
        else {
            $(element).fadeOut(500);
            setTimeout(function () {
                $(element).parent().addClass('display-none');
            }, 501);
        }
    };
}


function ValueTextHandler() {
    this.update = function (element, valueAccessor) {
        var value = valueAccessor();

        var selectedOption = $(element).find("option:selected");
        if (selectedOption.val() != "")
            value(selectedOption.text());
    };
}